import 'package:flutter/material.dart';
import 'package:power_house/pages/home/info/index.dart';
import 'package:power_house/room_detail/base_info_item.dart';
import 'package:power_house/widgets/common_swiper.dart';
import 'package:power_house/widgets/common_tag.dart';
import 'package:power_house/widgets/common_title.dart';
import 'package:power_house/widgets/room_appliance.dart';
import 'package:share_plus/share_plus.dart';

import 'data.dart';

const bottomTextStyle = TextStyle(fontSize: 18.0, color: Colors.white);

class RoomDetailPage extends StatefulWidget {
  final String roomId;

  const RoomDetailPage({Key? key, required this.roomId}) : super(key: key);

  @override
  State<RoomDetailPage> createState() => _RoomDetailPageState();
}

class _RoomDetailPageState extends State<RoomDetailPage> {
  late RoomDetailData data;
  bool isLike = false;
  bool showAllText = false;

  @override
  void initState() {
    super.initState();
    setState(() {
      data = defaultData;
    });
  }

  @override
  Widget build(BuildContext context) {
    bool showTextTool = data.subTitle.length > 100;

    return Scaffold(
      appBar: AppBar(
        title: Text(data.title),
        centerTitle: true,
        actions: [IconButton(onPressed: () => Share.share('https://blog.csdn.net/qq_57808875?spm=1000.2115.3001.5343'), icon: const Icon(Icons.share))],
      ),
      body: Stack(
        children: [
          ListView(
            children: [
              CommonSwiper(images: data.houseImages),
              Container(
                padding: const EdgeInsets.only(left: 10.0),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.end,
                  children: [
                    Text(
                      data.price.toString(),
                      style: const TextStyle(fontSize: 20.0, color: Colors.pink),
                    ),
                    const Text(
                      '元/月（押一付三）',
                      style: TextStyle(fontSize: 14.0, color: Colors.pink),
                    ),
                  ],
                ),
              ),
              Container(
                padding: const EdgeInsets.only(left: 10.0, top: 6.0, bottom: 6.0),
                child: Wrap(
                  spacing: 4.0,
                  children: data.tags.map((item) => CommonTag(item)).toList(),
                ),
              ),
              const Divider(
                color: Colors.grey,
                indent: 10.0,
                endIndent: 10.0,
              ),
              Container(
                padding: const EdgeInsets.only(left: 10.0, top: 6.0, bottom: 6.0),
                child: Wrap(
                  runSpacing: 20.0,
                  children: [
                    BaseInfoItem('面积:${data.size}平米'),
                    BaseInfoItem('楼层:${data.floor}平米'),
                    BaseInfoItem('房型:${data.roomType}平米'),
                    const BaseInfoItem('装修:精装'),
                  ],
                ),
              ),
              CommonTitle(data.title),
              const CommonTitle('房屋配置'),
              RoomFurnitureList(data.applicances),
              const CommonTitle('房屋概况'),
              Container(
                padding: const EdgeInsets.only(left: 10.0, right: 10.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      data.subTitle,
                      maxLines: showAllText ? null : 5,
                    ),
                    if (showTextTool)
                      GestureDetector(
                        onTap: () {
                          setState(() {
                            showAllText = !showAllText;
                          });
                        },
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [Text(showAllText ? '收起' : '展开'), Icon(showAllText ? Icons.keyboard_arrow_up : Icons.keyboard_arrow_down)],
                            ),
                            const Text(
                              '举报',
                              style: TextStyle(color: Colors.black, fontWeight: FontWeight.w600),
                            )
                          ],
                        ),
                      )
                    else
                      Container()
                  ],
                ),
              ),
              const CommonTitle('猜你喜欢'),
              const Info(),
              Container(
                height: 10.0,
              ),
            ],
          ),
          Positioned(
            width: MediaQuery.of(context).size.width,
            height: 100.0,
            bottom: 0,
            child: Container(
              color: Colors.grey[200],
              child: Row(
                children: [
                  GestureDetector(
                    onTap: () {
                      setState(() {
                        isLike = !isLike;
                      });
                    },
                    child: Container(
                      width: 60.0,
                      margin: const EdgeInsets.only(right: 10.0),
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Icon(
                            isLike ? Icons.star : Icons.star_border,
                            size: 34.0,
                            color: isLike ? Colors.green : Colors.black,
                          ),
                          Text(
                            isLike ? '已收藏' : '收藏',
                            style: const TextStyle(color: Colors.black, fontSize: 14.0),
                          )
                        ],
                      ),
                    ),
                  ),
                  Expanded(
                      child: GestureDetector(
                    onTap: () {},
                    child: Container(
                      margin: const EdgeInsets.only(right: 5.0),
                      alignment: Alignment.center,
                      height: 50.0,
                      decoration: BoxDecoration(color: Colors.cyan, borderRadius: BorderRadius.circular(6.0)),
                      child: const Text(
                        '联系房东',
                        textAlign: TextAlign.center,
                        style: bottomTextStyle,
                      ),
                    ),
                  )),
                  Expanded(
                      child: GestureDetector(
                    onTap: () {},
                    child: Container(
                      margin: const EdgeInsets.only(left: 5.0, right: 10.0),
                      alignment: Alignment.center,
                      height: 50.0,
                      decoration: BoxDecoration(color: Colors.green, borderRadius: BorderRadius.circular(6.0)),
                      child: const Text(
                        '预约看房',
                        textAlign: TextAlign.center,
                        style: bottomTextStyle,
                      ),
                    ),
                  )),
                ],
              ),
            ),
          )
        ],
      ),
    );
  }
}
